package hungle.oregonstate.edu.datastructure;

/**
 * The Class BinaryTreeNode.
 *
 * @param <K> the key type
 * @param <V> the value type
 */
public class BinaryTreeNode <K extends Comparable<K>, V>{
	
	/** The key. */
	private K key;
	
	/** The value. */
	private V value;
	
	/** The parent. */
	private BinaryTreeNode<K, V> parent = null;
	
	/** The left child. */
	private BinaryTreeNode<K, V> leftChild = null;
	
	/** The right child. */
	private BinaryTreeNode<K, V> rightChild = null;
	
	/**
	 * Instantiates a new binary tree node.
	 */
	public BinaryTreeNode(){}
	
	/**
	 * Instantiates a new binary tree node.
	 *
	 * @param key the key
	 * @param value the value
	 */
	public BinaryTreeNode(K key,V value){
		this.key = key;
		this.value = value;
	}
	
	/**
	 * Gets the key.
	 *
	 * @return the key
	 */
	public K getKey(){
		return key;
	}
	
	/**
	 * Gets the value.
	 *
	 * @return the value
	 */
	public V getValue(){
		return value;
	}
	
	/**
	 * Gets the parent.
	 *
	 * @return the parent
	 */
	public BinaryTreeNode<K, V> getParent(){
		return parent;
	}
	
	/**
	 * Gets the left child.
	 *
	 * @return the left child
	 */
	public BinaryTreeNode<K, V> getLeftChild(){
		return leftChild;
	}
	
	/**
	 * Gets the right child.
	 *
	 * @return the right child
	 */
	public BinaryTreeNode<K, V> getRightChild(){
		return rightChild;
	}
	
	/**
	 * Compare to.
	 *
	 * @param node the node
	 * @return the int
	 */
	public int compareTo(BinaryTreeNode<K,V> node){
		K key2 = node.getKey();
		return(key.compareTo(key2));
	}
	
	/**
	 * Checks for left child.
	 *
	 * @return true, if successful
	 */
	public boolean hasLeftChild(){
		return leftChild == null ? false : true;
	}
	
	/**
	 * Checks for right child.
	 *
	 * @return true, if successful
	 */
	public boolean hasRightChild(){
		return rightChild == null ? false : true;
	}
	
	/**
	 * Insert left.
	 *
	 * @param node the node
	 */
	public void insertLeft(BinaryTreeNode<K, V> node){
		leftChild = node;
	}
	
	/**
	 * Insert right.
	 *
	 * @param node the node
	 */
	public void insertRight(BinaryTreeNode<K, V> node){
		rightChild = node;
	}
	
	/**
	 * Update left.
	 *
	 * @param node the node
	 */
	public void updateLeft(BinaryTreeNode<K, V> node){
		leftChild = node;
	}
	
	/**
	 * Update right.
	 *
	 * @param node the node
	 */
	public void updateRight(BinaryTreeNode<K, V> node){
		rightChild = node;
	}
	
	/**
	 * Update the parent of the node
	 *
	 * @param node the node to be the new parent
	 */
	public void updateParent(BinaryTreeNode<K, V> node){
		parent = node;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString(){
		return key.toString() + " : " + value.toString();
	}
	
	

}
